﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        //运行这个程序的时候需要用到绝对路径
        static void Main(string[] args)
        {
            if (args.Count() == 0)
            {
                Console.WriteLine("请输入正确的文件夹和写入文件的路径");
            }
            else
            {

                switch (args[0])
                {

                    case "DirFileTreeinfo":
                        string param1 = args[1];
                        string param2 = args[3];
                        if (param1 == "-d" && param2 == "-o")
                        {
                            if (!System.IO.File.Exists(args[4]))
                            {
                                File.Create(args[4]);
                            }
                            else
                            {
                                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(args[2].ToString());
                                System.IO.StreamWriter objfile = new System.IO.StreamWriter(args[4]);
                                foreach (System.IO.FileInfo file in dir.GetFiles("*.*"))
                                {
                                    Console.WriteLine("{0},{1}", file.FullName, file.Length);
                                    objfile.WriteLine("{0},{1}", file.FullName.ToString(), file.Length.ToString());
                                }
                                foreach (System.IO.DirectoryInfo file1 in dir.GetDirectories())
                                {
                                    Console.WriteLine("{0}", file1.FullName);
                                    objfile.WriteLine("{0}", file1.FullName.ToString());
                                }
                                objfile.Close();
                            }
                        }


                        break;

                    case "CopyFile":
                        if (System.IO.Directory.Exists(args[1]))
                        {
                            if (!Directory.Exists(args[2]))
                            {
                                Directory.CreateDirectory(args[2]);
                            }
                            DirectoryInfo sDir = new DirectoryInfo(args[1]);
                            FileInfo[] fileArray = sDir.GetFiles();
                            foreach (FileInfo file in fileArray)
                            {

                                file.CopyTo(args[2] + "\\" + file.Name, true);
                            }
                            Console.WriteLine("{0}已经成功复制到{1}", args[1], args[2]);
                        }
                        else if (System.IO.File.Exists(args[1]))
                        {

                            FileInfo fi = new FileInfo(args[1]);
                            fi.CopyTo(args[2], true);
                            Console.WriteLine("{0}已经成功复制到{1}", args[1], args[2]);
                        }
                        break;
                    case"PickFile":
                        string parama = args[1];
                        string paramb = args[3];
                        string paramc=args[5];
                        if (parama == "-d" && paramb == "-t"&&paramc=="-o")
                        //-t 后面的文件请用“*.txt”这样的格式
                        {

                            var txtFiles = Directory.GetFiles(args[2], args[4]);
                          

                            foreach (string currentFile in txtFiles)
                            {
                                string fileName = currentFile.Substring(args[2].Length);
                                File.Copy(currentFile, args[6]+"\\"+ fileName,true);
                                Console.WriteLine("{0}已经成功复制到{1}", fileName,args[6]);
                              Console.WriteLine("{0}已经成功复{1}", fileName,args[6]);
                            }

                        } 
                        break;
                             

                }
            }

        }
    }
}